﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using S_Gridding.Api.Application.Commands.MeshType;
using S_Gridding.Infrastructure;

namespace S_Gridding.Api.Controllers
{
    /// <summary>
    /// 网络类型管理控制器
    /// </summary>

    [Route("api/[controller]/[action]")]
    [ApiController]
    // [ApiExplorerSettings(GroupName = nameof(ApiVersionInfo.网络类型管理))]
    [ApiExplorerSettings(GroupName =nameof(ApiVersionInfo.网络类型管理))]
    public class MeshTypeController : ControllerBase
    {
        private readonly SqlSugarDbContext _db;
        private readonly IMediator _mediator;  //注入中介者
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="db"></param>
        /// <param name="mediator"></param>
        public MeshTypeController(SqlSugarDbContext db, IMediator mediator)
        {
            _db = db;
            _mediator = mediator;
        }

        /// <summary>
        /// 表添加进mysql数据库中
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public string CreateTable()
        {
            _db.CreateDbContext();  //需要写上下文类里面的迁移方法
            return "ok";
        }

        /// <summary>
        /// sqlSuage 中介者添加网格类型管理信息
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> CreateMestType(MeshTypeSqlSuageCeateCommand m)
        {
            return await _mediator.Send(m);
        }

        /// <summary>
        /// 网格类型管理信息的单个真删除
        /// </summary>
        /// <returns></returns>
        [HttpDelete]
        public async Task<int> TrueDeleteMestType([FromQuery] MeshTypeSqlSuageTrueDeleteCommand m)
        {
            return await _mediator.Send(m);
        }

        /// <summary>
        /// 网格类型管理信息的单个逻辑删除
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<int> FalseDeleteMestType([FromQuery] MeshTypeSqlSuageFalseDeleteCommand m)
        {
            return await _mediator.Send(m);
        }

        /// <summary>
        /// 修改网格类型管理信息
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<int> UpdateMestType(MeshTypeSqlSuageUpdateCommand m)
        {
            return await _mediator.Send(m);
        }
    }
}
